const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const CopyPlugin = require('copy-webpack-plugin');
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const common = require('./webpack.common.js');
// const manifest = require('../dll/dll.manifest.json');

module.exports = merge(common, {
  mode: 'production',
  plugins: [
    new CopyPlugin([{ from: 'public', to: '.' } /* { from: 'dll', to: '.' } */]),
    // new webpack.DllReferencePlugin({
    //   manifest,
    //   context: path.resolve(__dirname, '../src'),
    // }),
    new ParallelUglifyPlugin({
      cacheDir: '.cache/',
      uglifyJS: {
        output: {
          beautify: false,
          comments: false,
        },
        compress: {
          drop_console: true,
        },
      },
    }),
  ],
  optimization: {
    splitChunks: {
      chunks: 'all',
      // 文件名连接符
      automaticNameDelimiter: '-',
      cacheGroups: {
        default: {
          name: 'common',
          chunks: 'all',
          minSize: 0,
          minChunks: 2,
          priority: -20,
          reuseExistingChunk: true,
        },
        vendor: {
          name: 'vendor',
          chunks: 'all',
          test: /[\\/]node_modules[\\/]/,
          priority: -10,
        },
      },
    },
    runtimeChunk: 'single',
    moduleIds: 'hashed',
    minimizer: [new OptimizeCSSAssetsPlugin({})],
  },
});
